package io.renren.modules.ypgl.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.ypgl.entity.YaopinkucunEntity;
import io.renren.modules.ypgl.service.YaopinkucunService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 药品库存管理
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2021-04-10 22:06:15
 */
@RestController
@RequestMapping("ypgl/yaopinkucun")
public class YaopinkucunController {
    @Autowired
    private YaopinkucunService yaopinkucunService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("ypgl:yaopinkucun:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = yaopinkucunService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("ypgl:yaopinkucun:info")
    public R info(@PathVariable("id") Integer id){
        YaopinkucunEntity yaopinkucun = yaopinkucunService.getById(id);

        return R.ok().put("yaopinkucun", yaopinkucun);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("ypgl:yaopinkucun:save")
    public R save(@RequestBody YaopinkucunEntity yaopinkucun){
        yaopinkucunService.save(yaopinkucun);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("ypgl:yaopinkucun:update")
    public R update(@RequestBody YaopinkucunEntity yaopinkucun){
        ValidatorUtils.validateEntity(yaopinkucun);
        yaopinkucunService.updateById(yaopinkucun);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("ypgl:yaopinkucun:delete")
    public R delete(@RequestBody Integer[] ids){
        yaopinkucunService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
